﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Index.cshtml";
}
<script>
    layui.use(['jquery', 'form', 'table', 'common', 'tablePlug'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table,
            common = layui.common;
        common.rendertable({
            elem: '#currentTableId',
            url: '/SystemSecurity/DbBackup/GetGridJson',
            page: false,
            cols: [[
                { field: 'F_Id', title: 'ID', sort: true, fixed: "left", hide: true, hideAlways: true },
                { field: 'F_DbName', title: '数据库名', width: 120, sort: true },
                { field: 'F_FileName', title: '备份名称', width: 200, sort: true },
                { field: 'F_FileSize', title: '大小', width: 100, sort: true },
                {
                    field: 'F_BackupType', title: '备份模式', width: 120, sort: true, fixed: "left", filter: true,
                    templet: function (d) {
                        if (d.F_BackupType == "1") {
                            return "完整备份";
                        } else {
                            return "差异备份";
                        }
                    }
                },
                {
                    field: 'F_CreatorTime', title: '备份时间', width: 120, sort: true,
                    templet: function (d) {
                        if (d.F_CreatorTime) {
                            var time = new Date(d.F_CreatorTime);
                            return time.getFullYear() + "-" + (time.getMonth() + 1) + "-" + time.getDate();
                        }
                    }
                },
                { field: 'F_Description', title: '备注', width: 150, sort: true },
            ]],
        });
        //权限控制
        common.authorizeButton("toolbar");
        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            var queryJson = JSON.stringify(data.field);
            //执行搜索重载
            common.reloadtable({
                elem: 'currentTableId',
                page: false,
                curr: 1,
                where: { keyword: data.field.txt_keyword }
            });
            return false;
        });
        var Db;
        //行点击监听
        table.on('row(currentTableFilter)', function (obj) {
            obj.tr.addClass("layui-table-click").siblings().removeClass("layui-table-click");
            Db = obj;
        })
        /**
         * toolbar监听事件
         */
        table.on('toolbar(currentTableFilter)', function (obj) {
            if (obj.event === 'add') {  // 监听删除操作
                common.modalOpen({
                    title: "添加备份",
                    url: "/SystemSecurity/DbBackup/Form",
                    width: "450px",
                    height: "420px",
                });
            }
            else if (obj.event === 'delete') {
                if (Db == null) {
                    common.modalMsg("未选中数据", "warning");
                    return false;
                }
                common.deleteForm({
                    url: "/SystemSecurity/DbBackup/DeleteForm",
                    param: { keyValue: Db.data.F_Id },
                    success: function () {
                        common.reload('data-search-btn');
                    }
                });
            }
            else if (obj.event === 'download'){
                if (Db == null) {
                    common.modalMsg("未选中数据", "warning");
                    return false;
                }
                common.download("/SystemSecurity/DbBackup/DownloadBackup", "keyValue=" + Db.data.F_Id, 'post');
            }
            return false;
        });
    });
</script>
<div class="layuimini-container">
    <div class="layuimini-main">

        <fieldset class="table-search-fieldset">
            @*<legend>搜索信息</legend>*@
            <div style="margin: 10px 10px 10px 10px">
                <form class="layui-form layui-form-pane" action="">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">关键字:</label>
                            <div class="layui-input-inline">
                                <input type="text" id="txt_keyword" name="txt_keyword" autocomplete="off" class="layui-input" placeholder="">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button type="submit" class="layui-btn layui-btn-primary" lay-submit lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
                        </div>
                    </div>
                </form>
            </div>
        </fieldset>

        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container" id="toolbar">
                <button id="NF-add" authorize="yes" class="layui-btn layui-btn-sm data-add-btn" lay-event="add"><i class="layui-icon">&#xe654;</i>新建</button>
                <button id="NF-delete" authorize="yes" class="layui-btn layui-btn-sm layui-btn-danger data-delete-btn" lay-event="delete"> <i class="layui-icon">&#xe640;</i>删除</button>
                <button id="NF-download" authorize="yes" class="layui-btn layui-btn-sm layui-btn-normal data-info-btn" lay-event="download"> <i class="layui-icon">&#xe601;</i>下载</button>
            </div>
        </script>

        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

    </div>
</div>